﻿using API.Common;
using API.ServiceHost;
using ServiceStack.Text;

namespace CrossDomainAccess
{
    public class AppInit : AppHostBase
    {
        public override void Init()
        {
            JsConfig.ThrowOnDeserializationError = true;
            RegisterValidators(typeof(AppInit).Assembly);

            RequestFilters.Insert(0, (req, res, obj) =>
            {
                if (req.Headers[HttpHeaders.Origin] != null)
                {
                    res.AddHeader(HttpHeaders.AllowOrigin, req.Headers[HttpHeaders.Origin]);
                }
                if (req.Headers[HttpHeaders.RequestHeaders] != null)
                {
                    res.AddHeader(HttpHeaders.AllowHeaders, req.Headers[HttpHeaders.RequestHeaders]);
                }
            });
        }
    }
}
